use thiserror::Error;

#[derive(Error, Debug)]
pub enum EdgeError {
    #[error("toml.de: {0}")]
    TomlDe(#[from] toml::de::Error),

    #[error("tera: {0}")]
    Tera(#[from] tera::Error),

    #[error("i/o: {0}")]
    IO(#[from] std::io::Error),

    #[error("json.serde: {0}")]
    JsonSerDe(#[from] serde_json::Error),

    //#[error("Invalid file name")]
    //UnconvertableFileName,

    #[error("markdown parse: {0}")] 
    MdParse(String),

    #[error("no front matter in markdown, file={0}")]
    NoFrontMatter(String),

    #[error("collection not found: {0}")]
    NoCollection(String),

    #[error("resource not found: {0}[{1}]/{2}")]
    ResourceNotFound(String, String, String),

    #[error("invalid header value: {0}")]
    InvalidHeaderValue(#[from] axum::http::header::InvalidHeaderValue),

    #[error("auth: {0}")]
    Auth(#[from] auth::AuthError),

    #[error("[{0}: {1}] {2}")]
    Context(&'static str, String, Box<Self>),
}

pub type Result<T, E=EdgeError> = std::result::Result<T, E>;